$(document).ready(function () { $("nav ul li:has(ul)").addClass('hasChildren'); Array.from($("nav>ul>li>ul>li:not(.hasChildren)")).forEach(element => { const data = $(element).data("hasnochildren"); if (data && data.toLowerCase() === "true") { $(element).addClass('hasNoChildren'); } }); $('[role=menubar] li').each(function () { if ($(this).find('>a').length <= 0) { $(this).find('>span.title').attr('has-popup', true); $(this).find('>span.title').attr('aria-expanded', false); } }); if (isTouchScreendevice()) { //alert("I am a touch screen device"); // Console.log("I am a touch screen device"); //Make both span and caret clickable SetupMenuButton(); SetupMobileMenu(); CloseOpenedMenus(); } else { //Make both span and caret clickable SetupMenuButton(); SetupMenu(); SetupSpanClick(); } SetHeaderBlockSticky(); }); function isTouchScreendevice() { /* browser with either Touch Events of Pointer Events running on touch-capable device */ return ('ontouchstart' in window) || (navigator.maxTouchPoints); } function menuTitleClick(e) { const menuitems = document.querySelectorAll('nav ul li.hasChildren'); if (menuitems != null) { Array.prototype.forEach.call(menuitems, function (el) { var accessel = el.querySelector('span'); if (e.currentTarget != accessel) { $(accessel).closest("li").removeClass('menuOpened'); $(accessel).closest("li").attr('aria-expanded', false); $(accessel).attr('aria-expanded', false); $(accessel).closest("li").find('>button').attr('aria-expanded', false); } }); if ($(this).closest("li").hasClass('isGroup') || $(this).closest("ul").hasClass('isGroup')) { $(this).closest('li').parents('.hasChildren').addClass('menuOpened').attr('aria-expanded', true); } if ($(this).closest("li").hasClass('menuOpened')) { $(this).closest("li").removeClass('menuOpened'); $(this).closest("li").attr('aria-expanded', false); $(this).attr('aria-expanded', false); } else { $(this).closest("li").addClass('menuOpened'); $(this).closest("li").attr('aria-expanded', true); $(this).attr('aria-expanded', true); } } e.stopPropagation(); e.preventDefault(); } function SetupMobileMenu() { $("nav ul li:has(ul) > span.title").off('click touchstart'); $("nav ul li:has(ul) > span.title").on('click touchstart', menuTitleClick); if ($("nav>ul>li.hasChildren")) $("nav>ul").attr('role', 'menubar'); $("nav ul li.hasChildren").each(function () { $(this).attr('role', 'none'); $(this).children("ul").attr('aria-label', $(this).children(".title").text()); }); $(document).on('click', 'body.menu-open', function (e) { if (!($(e.target).parents('.globalNav').length > 0 || $(e.target).parents('.secondaryNav').length > 0)) $('body').toggleClass('menu-open'); }); $(document).on('click', '#siteMenuToggle', function (e) { $('body').toggleClass('menu-open'); e.preventDefault(); e.stopPropagation(); }); $('.modalPopupMenuItem').magnificPopup({ type: 'inline', midClick: true }); } function SetupSpanClick() { $("nav ul li:has(ul) > span.title").on('click', menuTitleClick); } function SetupMenuButton() { const menuItems = document.querySelectorAll('nav ul li.hasChildren'); Array.prototype.forEach.call(menuItems, function (el) { el.querySelector('button').addEventListener("click", function (event) { menuItems.forEach(function (singlemenu) { if (singlemenu != el) { singlemenu.classList.remove("menuOpened"); } }); if ($(this).closest("li").hasClass('isGroup') || $(this).closest("ul").hasClass('isGroup')) { $(this).closest('li').parents('.hasChildren').addClass('menuOpened').attr('aria-expanded', true); } if ($(this).closest("li").hasClass('menuOpened')) { $(this).closest("li").removeClass('menuOpened'); $(this).closest("li").attr('aria-expanded', false); $(this).attr('aria-expanded', false); } else { $(this).closest("li").addClass('menuOpened'); $(this).closest("li").attr('aria-expanded', true); $(this).attr('aria-expanded', true); } const focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); event.preventDefault(); }); }); } function CloseOpenedMenus() { $('.resort-header').click(function (e) { var containerSecondaryNav = $('.pagelistmenuitemblock'); var containerGlobalNav = $('.menulinklistblock'); var languageSelectorBlock = $('.languageselectormenuitemblock'); var menuItemBlock = $('.menuitemblock'); if (!containerGlobalNav.is(e.target) && containerGlobalNav.has(e.target).length === 0) { if (containerGlobalNav.hasClass('menuOpened')) { containerGlobalNav.removeClass('menuOpened'); containerGlobalNav.attr('aria-expanded', false); } } if (!containerSecondaryNav.is(e.target) && containerSecondaryNav.has(e.target).length === 0) { if (containerSecondaryNav.hasClass('menuOpened')) { containerSecondaryNav.removeClass('menuOpened'); containerSecondaryNav.attr('aria-expanded', false); } } if (!languageSelectorBlock.is(e.target) && languageSelectorBlock.has(e.target).length === 0) { if (languageSelectorBlock.hasClass('menuOpened')) { languageSelectorBlock.removeClass('menuOpened'); languageSelectorBlock.attr('aria-expanded', false); } } if (!menuItemBlock.is(e.target) && menuItemBlock.has(e.target).length === 0) { if (menuItemBlock.hasClass('menuOpened')) { menuItemBlock.removeClass('menuOpened'); menuItemBlock.attr('aria-expanded', false); } } }); } function SetupMenu() { var countElement = 0; var accessElement; CloseOpenedMenus(); if ($("nav>ul>li.hasChildren")) $("nav>ul").attr('role', 'menubar'); $("nav ul li.hasChildren").each(function () { $(this).attr('role', 'none'); $(this).children("ul").attr('aria-label', $(this).children(".title").text()); }); $(document).on('keydown', '.pagelistmenuitemblock', function (e) { if (e.keyCode == 40) { accessElement = $(this).children('ul').find('a'); if (accessElement.length >= 1) { if (countElement == accessElement.length) { $(this).removeClass('menuOpened'); countElement = 0; //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } // $(accessElement[countElement]).focus(); $(accessElement[countElement]).attr("tabindex", "0").focus(); countElement = countElement + 1; } } if (e.keyCode == 38) { //Focus on next item in list for Up arrow key accessElement = $(this).children('ul').find('a'); if (countElement == 0) { $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { // var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } else if (countElement > 0) { countElement = countElement - 1; $(accessElement[countElement]).attr("tabindex", "0").focus(); } } else if (e.keyCode == 27) { countElement = 0; accessElement = null; $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } } //Close Navigation menu when last element is tabbed if (e.keyCode == 9 && !(e.shiftKey)) { countElement = 0; var $deepEl; $(this).find("li").each(function (index, me) { $deepEl = me; }); var lastAnchor = $($deepEl).find('a'); var target = e.target; if (target !== undefined && $(target).is('a')) { if ($(target).attr('href') == lastAnchor.attr('href')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } //Close Navigation menu when menu is shift-tabbed and no active element if (e.shiftKey && e.keyCode == 9) { if ($(this).find('button').is(e.target)) { if ($(this).hasClass('menuOpened')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } }); $(document).on('keydown', '.menulinklistblock', function (e) { if (e.keyCode == 40) { accessElement = $(this).children('ul').find('a'); if (accessElement.length >= 1) { if (countElement == accessElement.length) { $(this).removeClass('menuOpened'); countElement = 0; //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } // $(accessElement[countElement]).focus(); $(accessElement[countElement]).attr("tabindex", "0").focus(); countElement = countElement + 1; } } if (e.keyCode == 38) { accessElement = $(this).children('ul').find('a'); if (countElement == 0) { $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { // var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } else if (countElement > 0) { countElement = countElement - 1; $(accessElement[countElement]).attr("tabindex", "0").focus(); } } else if (e.keyCode == 27) { countElement = 0; accessElement = null; $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } } //Close Navigation menu when last element is tabbed if (e.keyCode == 9 && !(e.shiftKey)) { var $deepEl; $(this).find("li").each(function (index, me) { $deepEl = me; }); var lastAnchor = $($deepEl).find('a'); var target = e.target; if (target !== undefined && $(target).is('a')) { if ($(target).attr('href') == lastAnchor.attr('href')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } //Close Navigation menu when menu is shift-tabbed and no active element if (e.shiftKey && e.keyCode == 9) { if ($(this).find('button').is(e.target)) { if ($(this).hasClass('menuOpened')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } }); $(document).on('keydown', '.languageselectormenuitemblock', function (e) { if (e.keyCode == 40) { accessElement = $(this).children('ul').find('a'); if (accessElement.length >= 1) { if (countElement == accessElement.length) { $(this).removeClass('menuOpened'); countElement = 0; //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } // $(accessElement[countElement]).focus(); $(accessElement[countElement]).attr("tabindex", "0").focus(); countElement = countElement + 1; } } if (e.keyCode == 38) { accessElement = $(this).children('ul').find('a'); if (countElement == 0) { $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { // var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } else if (countElement > 0) { countElement = countElement - 1; $(accessElement[countElement]).attr("tabindex", "0").focus(); } } else if (e.keyCode == 27) { countElement = 0; accessElement = null; $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } } //Close Navigation menu when last element is tabbed if (e.keyCode == 9 && !(e.shiftKey)) { countElement = 0; var $deepEl; $(this).find("li").each(function (index, me) { $deepEl = me; }); var lastAnchor = $($deepEl).find('a'); var target = e.target; if (target !== undefined && $(target).is('a')) { if ($(target).attr('href') == lastAnchor.attr('href')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } //Close Navigation menu when menu is shift-tabbed and no active element if (e.shiftKey && e.keyCode == 9) { if ($(this).find('button').is(e.target)) { if ($(this).hasClass('menuOpened')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } }); $(document).on('keydown', '.menuitemblock', function (e) { if (e.keyCode == 40) { accessElement = $(this).children('ul').find('a'); if (accessElement.length >= 1) { if (countElement == accessElement.length) { $(this).removeClass('menuOpened'); countElement = 0; //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } // $(accessElement[countElement]).focus(); $(accessElement[countElement]).attr("tabindex", "0").focus(); countElement = countElement + 1; } } if (e.keyCode == 38) { accessElement = $(this).children('ul').find('a'); if (countElement == 0) { $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { // var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } return; } else if (countElement > 0) { countElement = countElement - 1; $(accessElement[countElement]).attr("tabindex", "0").focus(); } } else if (e.keyCode == 27) { countElement = 0; accessElement = null; $(this).removeClass('menuOpened'); //focus next menu item if there is list available next if ($(this).next().find('span.title').length > 1) { //var focusElem = $(this).next().find('span.title').first(); var focusElem = $(this).next().find('button'); focusElem.attr("tabindex", "0"); focusElem.focus(); } else if ($(this).next().find('span.title').length == 1) { var focusElem = $(this).next().find('a'); //var focusElem = $(this).next(); focusElem.attr("tabindex", "0"); focusElem.focus(); } // focus next menu if no list available next else { var menuBlock = $(this).closest(".block"); if (menuBlock.next().length > 0) { var focusElem = menuBlock.next().find('span.title').first(); focusElem.attr("tabindex", "0"); focusElem.focus(); } } } //Close Navigation menu when last element is tabbed if (e.keyCode == 9 && !(e.shiftKey)) { countElement = 0; var $deepEl; $(this).find("li").each(function (index, me) { $deepEl = me; }); var lastAnchor = $($deepEl).find('a'); var target = e.target; if (target !== undefined && $(target).is('a')) { if ($(target).attr('href') == lastAnchor.attr('href')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } //Close Navigation menu when menu is shift-tabbed and no active element if (e.shiftKey && e.keyCode == 9) { if ($(this).find('button').is(e.target)) { if ($(this).hasClass('menuOpened')) { $(this).removeClass('menuOpened'); $(this).attr('aria-expanded', false); } } } }); $(document).on('click', 'body.menu-open', function (e) { if (!($(e.target).parents('.globalNav').length > 0 || $(e.target).parents('.secondaryNav').length > 0)) $('body').toggleClass('menu-open'); }); $(document).on('click', '#siteMenuToggle', function (e) { $('body').toggleClass('menu-open'); e.preventDefault(); e.stopPropagation(); }); $('.modalPopupMenuItem').magnificPopup({ type: 'inline', midClick: true }); } // Header stickybar function SetHeaderBlockSticky() { var mainBlock = $('body').hasClass('mobile-sticky-booking'); if (mainBlock) { sticky = new Waypoint.Sticky({ element: $('.headerBlock') }); } }